package com.lanxiaoye.shoppingSystem.common.page;

import java.io.Serializable;

/**
 * Created by libing on 2017/3/2.
 */
public class Page implements Serializable {

    public Integer currentPage;
    public Integer pageSize = 3;
    public Integer totalPage;
    public Integer totalRows;
    public Integer startIndex;
    public Integer endIndex;

    public static Page instance(Integer currentPage,Integer pageSize){
        Page page = new Page();
        page.setCurrentPage(currentPage);
        page.setPageSize(pageSize);
        return page;
    }

    public Integer getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(Integer startIndex) {
        this.startIndex = startIndex;
    }

    public Integer getEndIndex() {
        return endIndex;
    }

    public void setEndIndex(Integer endIndex) {
        this.endIndex = endIndex;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
        this.startIndex = (this.currentPage - 1) * this.pageSize;
        this.endIndex = this.currentPage * this.pageSize;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalPage() {
        if (this.totalRows % this.pageSize == 0) {
            this.totalPage = this.totalRows / this.pageSize;
        } else {
            this.totalPage = this.totalRows / this.pageSize + 1;
        }
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getTotalRows() {
        return totalRows;
    }

    public void setTotalRows(Integer totalRows) {
        this.totalRows = totalRows;
    }

}
